package com.yh.commentmongodb.service.impl;

import com.yh.commentmongodb.dao.CommentDao;
import com.yh.commentmongodb.entity.Comment;
import com.yh.commentmongodb.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author wannabe
 * @createTime 23 17:15
 * @description
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentDao commentDao;
    @Override
    public List<Comment> findAll() {
        return commentDao.findAll();
    }

    @Override
    public Comment getComment(String id) {
        return commentDao.getComment(id);
    }

    @Override
    public void update(Comment comment) {
        commentDao.update(comment);
    }

    @Override
    public void insert(Comment comment) {
        comment.setArticleid("1001");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-hh");
        comment.setCreatedatetime(simpleDateFormat.format(new Date()));
        comment.setNickname("游客");
        comment.setLikenum(0);
        comment.setParentid("0");
        comment.setState(1);
        comment.setReplynum(0);
        comment.setUserid("1");
        commentDao.insert(comment);
    }

    @Override
    public void insertAll(List<Comment> comment) {
        commentDao.insertAll(comment);
    }

    @Override
    public void remove(String id) {
        commentDao.remove(id);
    }
}